import Vue from 'vue'
import VueRouter from 'vue-router'
import { shopLayout, mainLayout, pageLayout } from '@/layout'

Vue.use(VueRouter)

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
// 业务路由
export const service = [
  {
    path: '/',
    name: 'page',
    meta: { title: '首页' },
    component: mainLayout,
    redirect: '/oa',
    children: [
      {
        path: '/point',
        name: 'point',
        meta: { title: '地图', desc: '地图', icon: 'el-icon-map-location' },
        component: shopLayout,
        redirect: '/point/map',
        children: [
          {
            path: '/point/map',
            name: 'pointMap',
            meta: { title: '公交地图列表' },
            component: () => import(/* webpackChunkName: "map" */ '@/views/bus')
          }
        ]
      },
      // {
      //   path: '/point/share',
      //   name: 'pointShare',
      //   meta: { title: '预选点位图' },
      //   component: () => import(/* webpackChunkName: "map" */ '@/views/share')
      // }
      {
        path: '/form',
        name: 'form',
        meta: { title: '表单', desc: '地图', icon: 'el-icon-tickets' },
        component: pageLayout,
        redirect: '/form/map',
        children: [
          {
            path: '/form/map',
            name: 'formMap',
            meta: { title: '公交地图列表' },
            component: () => import(/* webpackChunkName: "map" */ '@/views/form')
          }
        ]
      },
      // {
      //   path: '/week',
      //   name: 'week',
      //   meta: { title: '周报', desc: '周报', icon: 'el-icon-s-goods' },
      //   component: pageLayout,
      //   redirect: '/form/week',
      //   children: [
      //     {
      //       path: '/form/week',
      //       name: 'formWeek',
      //       meta: { title: '周报' },
      //       component: () => import(/* webpackChunkName: "map" */ '@/views/week')
      //     }
      //   ]
      // },
      // {
      //   path: '/douyin',
      //   name: 'douyin',
      //   meta: { title: '抖音', desc: '抖音', icon: 'el-icon-s-goods' },
      //   component: pageLayout,
      //   redirect: '/form/douyin',
      //   children: [
      //     {
      //       path: '/form/douyin',
      //       name: 'formDouyin',
      //       meta: { title: '抖音' },
      //       component: () => import(/* webpackChunkName: "map" */ '@/views/douyin')
      //     }
      //   ]
      // },
      {
        path: '/oa',
        name: 'oa',
        meta: { title: '办公', desc: '流程', icon: 'el-icon-monitor' },
        component: pageLayout,
        redirect: '/oa/list',
        children: [
          {
            path: '/oa/list',
            name: 'oaList',
            meta: { title: 'OA' },
            component: () => import(/* webpackChunkName: "map" */ '@/views/oa/list.vue')
          },
          {
            path: '/oa/main',
            name: 'oaMain',
            meta: { title: 'OA' },
            component: () => import(/* webpackChunkName: "map" */ '@/views/oa/index.vue')
          }
        ]
      },
      {
        path: '/photo',
        name: 'photo',
        meta: { title: '照片', desc: '照片', icon: 'el-icon-picture-outline' },
        component: pageLayout,
        redirect: '/photo',
        children: [
          {
            path: '/photo',
            name: 'photo',
            meta: { title: 'photo' },
            component: () => import(/* webpackChunkName: "map" */ '@/views/photo/index.vue')
          }
        ]
      }
    ]
  }
]

// 用户路由 此部分不参与权限校验
const user = [
  {
    path: '/user',
    name: 'user',
    component: mainLayout,
    redirect: '/user/login',
    children: [
      {
        path: '/user/login',
        name: 'userLogin',
        meta: { title: '登录' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/login')
      },
      {
        path: '/user/register',
        name: 'userRegister',
        meta: { title: '注册' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/register')
      },
      {
        path: '/user/forget',
        name: 'userForget',
        meta: { title: '忘记密码' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/forget')
      },
      {
        path: '/401',
        name: '401',
        meta: { title: '401' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/exception/401')
      },
      {
        path: '/403',
        name: '403',
        meta: { title: '403' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/exception/403')
      },
      {
        path: '/404',
        name: '404',
        meta: { title: '404' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/exception/404')
      },
      {
        path: '/share',
        name: 'share',
        meta: { title: '周报', desc: '周报', icon: 'el-icon-s-goods' },
        component: mainLayout,
        redirect: '/share/map',
        children: [
          {
            path: '/share/map',
            name: 'shareMap',
            meta: { title: '分享点位图' },
            component: () => import(/* webpackChunkName: "map" */ '@/views/share')
          }
        ]
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'hash',
  // base: process.env.BASE_URL,
  base: '/teadmedia',
  routes: service.concat(user)
})

export default router
